<!DOCTYPE html>
<html lang="en" xml:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户编辑</title>
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<div class="layui-container" style="width:600px;">
    <form action="" class="layui-form layui-form-pane" lay-filter="userInfo">
        <input hidden name="id" th:value="${entity.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input autocomplete="off" class="layui-input" name="username" placeholder="请输入学号/工号"
                       th:value="${entity.username}"
                       type="username">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-label ">姓名</div>
            <div class="layui-input-block">
                <input autocomplete="off" class="layui-input" name="name" placeholder="请输入姓名"
                       th:value="${entity.nickName}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-label ">昵称</div>
            <div class="layui-input-block">
                <input autocomplete="off" class="layui-input" name="nickName" placeholder="请输入昵称"
                       th:value="${entity.nickName}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-label ">邮箱</div>
            <div class="layui-input-block">
                <input autocomplete="off" class="layui-input" name="email" placeholder="请输入手机号" th:value="${entity.email}"
                       type="email">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input checked lay-filter="switch" lay-skin="switch" lay-text="启用|禁用" name="status"
                       th:value="${entity.status}" type="checkbox">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="submit" lay-submit="" type="submit">保存</button>
            </div>
        </div>
    </form>
</div>
</body>

<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<script>
    layui.use(['jquery', 'form'], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form;

        //监听指定开关
        form.on('switch(switch)', function () {
            $(".layui-container input[name=status]").attr('type', 'hidden').val(this.checked ? 1 : 2);
        });

        //监听提交
        form.on('submit(submit)', function (data) {
            if (data.field.username.length !== 7) {
                layer.msg("用户名必须是7位")
                return
            }
            CoreUtil.sendAjax("/elective/user/update", JSON.stringify(data.field), function (res) {
                layer.msg(res.msg);
            }, "PUT", false);
            return false;
        });


    });
</script>
</html>
